<?php
Class uploader
{
      /**
    * @desc Type of incoming data
    * @access   public
    * @var  string 
    */
    public $in_type          = 'file';

    /**
    * @desc Type of outgoing data
    * @access   public
    * @var  string 
    */
    public $out_type         = 'file';

    /**
    * @desc Save file as...
    * @access   public
    * @var  string 
    */
    public $out_file_name    = '';

    /**
    * @desc Save file in...
    * @access   public
    * @var  string 
    */
    public $out_file_dir     = '';

    /**
    * @desc In file directory
    * @access   public
    * @var  string 
    */
    public $in_file_dir      = '.';

    /**
    * @desc Name of input file name
    * @access   public
    * @var  string 
    */
    public $in_file_name     = '';

    /**
    * @desc Complete file name with path
    * @access   public
    * @var  string
    */
    public $in_file_complete = '';

    /**
    * @desc Max. thumbnail width
    * @access   public
    * @var  integer 
    */
    public $desired_width    = 0;

    /**
    * @desc Max. thumbnail height
    * @access   public
    * @var  integer Pixels
    */
    public $desired_height   = 0;

    /**
    * @desc GD version
    * @access   public
    * @var  integer    
    */
    public $gd_version       = 2;

    /**
    * @desc Image type (PNG, JPG, GIF)
    * @access   public
    * @var  string 
    */
    public $image_type       = '';

    /**
    * @desc File extension
    * @access   public
    * @var  string
    */
    public $file_extension   = '';  
    
    private $config;     
    
    public function __construct()
    {
        require_once 'upload.conf.php';
        $this->config = $upload_config;
    }      
    // Upload file to server
    //Param: $file: file posted
    //Param: $dir: Folder name to store file
    public function upload($file, $dir_name){
        $result_data = array();
        $this_config = $this->config['upload_dirs'][ $dir_name ];
        $dir_store = $this_config['file_dir'];
        $file_name = $_FILES[$file]["name"];

        if ((($_FILES[$file]["type"] == "image/gif") || ($_FILES[$file]["type"] == "image/jpeg") || ($_FILES[$file]["type"] == "image/pjpeg") || ($_FILES[$file]["type"] == "image/jpg")) && ($_FILES[$file]["size"] < 20971520))
          {
          if ($_FILES[$file]["error"] > 0)
            {
            $result_data['error'] = FILE_ERROR;
            }
          else
            {
            if (file_exists($dir_store . $_FILES[$file]["name"]))
              {
               $result_data['error'] = FILE_EXISTS; 
              }
            else
              {
              move_uploaded_file($_FILES[$file]["tmp_name"], $dir_store . $file_name);
              }
            }
          }
        else
          {
          $result_data['error'] = FILE_INVALID_TYPE; 
          }
        
        if($result_data['error'] ==0 || $result_data['error'] == FILE_EXISTS){  
            $this->_build_thumbnails($dir_name, $file_name);
        }
        //Return data to database
        $result_data['name'] = $file_name;
        $result_data['size'] = number_format(($_FILES[$file]["size"] / 1048576),2) . 'MB'; 
        isset($result_data['error'])?intval($result_data['error']):0;
        return $result_data;
  }
  private function _build_thumbnails($dir_name, $file_with_ext){
        $this_config = $this->config['upload_dirs'][ $dir_name ];
        $file_name = $this->_get_file_name($file_with_ext);
        //$hash_dir = $this->_get_hash_value($hash_id);

        //===========================================================================
        // create thumbnails
        //===========================================================================
        if (isset($this_config['thumbs'])){
            foreach ($this_config['thumbs'] as $thumb_config) {
                //$this->file_handler->mkdir($thumb_config['file_dir'].$hash_dir);
                $this->in_file_dir            =    $this_config['file_dir'];
                $this->out_file_dir            =     $thumb_config['file_dir'];
                $this->in_file_name            =     $file_with_ext;
                $this->out_file_name            =     $file_name;
                $this->desired_width          =     $thumb_config['width'];
                $this->desired_height         =     $thumb_config['height'];

                if ($thumb_config['thumbnail_type'] == 'resize') {
                    $resized = $this->generate_thumbnail();
                }
                else {
                    $resized = $this->generate_crop_thumbnail();
                }

                if ($resized == false)
                {
                    copy(
                        $this_config['file_dir']. DIRECTORY_SEPARATOR . $file_with_ext,
                        $thumb_config['file_dir']. DIRECTORY_SEPARATOR . $file_with_ext
                    );
                }
            }
        }
    }
      /**
    * @desc Cleans up paths, generates var $in_file_complete
    * @access   private
    * @param    void
    * @return   void
    * @internal
    */
    private function _clean_paths()
    {
        $this->in_file_dir  = preg_replace( "#/$#", "", $this->in_file_dir );
        $this->out_file_dir = preg_replace( "#/$#", "", $this->out_file_dir );

        if ( $this->in_file_dir and $this->in_file_name )
        {
            $this->in_file_complete = $this->in_file_dir.'/'.$this->in_file_name;
        }
        else
        {
            $this->in_file_complete = $this->in_file_name;
        }

        if ( ! $this->out_file_dir )
        {
            $this->out_file_dir = $this->in_file_dir;
        }
    }
     /**
    *   @desc        return the file name of the file with full ext
    *
    *   @access        private
    *    @param        string
    *   @returns    string
    */
    private function _get_file_name($file_with_ext){
        $ext = strrchr($file_with_ext, '.');
        if ($ext){
               $file_name = substr($file_with_ext, 0, -strlen($ext));
               return $file_name;
          }
          return '';
    }
      /**
    * @desc Generates thumnbail
    * @access   public   
    * @param    void
    * @return   array    [ thumb_width, thumb_height, thumb_location ]
    */
    public function generate_thumbnail()
    {
        $return = array();
        $image  = "";
        $thumb  = "";

        //-----------------------------------
        // Set up paths
        //-----------------------------------

        $this->_clean_paths();

        $remap  = array( 1 => 'GIF', 2 => 'JPG', 3 => 'PNG', 4 => 'SWF', 5 => 'PSD', 6 => 'BMP' );

        if ( $this->desired_width and $this->desired_height )
        {
            //----------------------------------------------------
            // Tom Thumb!
            //----------------------------------------------------

            $img_size = array();

            if ( $this->in_type == 'file' )
            {
                $img_size = @GetImageSize( $this->in_file_complete );
            }

            if ( $img_size[0] < 1 and $img_size[1] < 1 )
            {
                $img_size    = array();
                $img_size[0] = $this->desired_width;
                $img_size[1] = $this->desired_height;

                $return['thumb_width']    = $this->desired_width;
                $return['thumb_height']   = $this->desired_height;

                if ( $this->out_type == 'file' )
                {
                    $return['thumb_location'] = $this->in_file_name;
                    return $return;
                }
                else
                {
                    //----------------------------------------------------
                    // Show image
                    //----------------------------------------------------

                    $this->_show_non_gd();
                }
            }

            //----------------------------------------------------
            // Do we need to scale?
            //----------------------------------------------------

            if ( ( $img_size[0] > $this->desired_width ) OR ( $img_size[1] > $this->desired_height ) )
            {

                $im = $this->scale_image( array(
                                                 'max_width'  => $this->desired_width,
                                                 'max_height' => $this->desired_height,
                                                 'cur_width'  => $img_size[0],
                                                 'cur_height' => $img_size[1]
                                        )      );

                $return['thumb_width']     = $im['img_width'];
                $return['thumb_height']    = $im['img_height'];
                $return['original_width']  = $img_size[0];
                $return['original_height'] = $img_size[1];

                //-----------------------------------------------
                // May as well scale properly.
                //-----------------------------------------------

                if ( $im['img_width'] )
                {
                    $this->desired_width = $im['img_width'];
                }

                if ( $im['img_height'] )
                {
                    $this->desired_height = $im['img_height'];
                }

                //-----------------------------------------------
                // GD functions available?
                //-----------------------------------------------

                if ( $remap[ $img_size[2] ] == 'GIF' )
                {
                    if ( function_exists( 'imagecreatefromgif') )
                    {
                        if ( $image = @imagecreatefromgif( $this->in_file_complete ) )
                        {
                            $this->image_type = 'gif';
                        }
                        else
                        {
                            if ( $this->out_type == 'file' )
                            {
                                $return['thumb_width']     = $this->desired_width;
                                $return['thumb_height']    = $this->desired_height;
                                $return['thumb_location']  = $this->in_file_name;
                                $return['original_width']  = $img_size[0];
                                $return['original_height'] = $img_size[1];
                            }
                            else
                            {
                                //-----------------------------------------------
                                // Show Image..
                                //-----------------------------------------------

                                $this->_show_non_gd();

                            }
                        }
                    }
                }
                else if ( $remap[ $img_size[2] ] == 'PNG' )
                {
                    if ( function_exists( 'imagecreatefrompng') )
                    {
                        if ( $image = @imagecreatefrompng( $this->in_file_complete ) )
                        {
                            $this->image_type = 'png';
                        }
                        else
                        {
                            if ( $this->out_type == 'file' )
                            {
                                $return['thumb_width']     = $this->desired_width;
                                $return['thumb_height']    = $this->desired_height;
                                $return['thumb_location']  = $this->in_file_name;
                                $return['original_width']  = $img_size[0];
                                $return['original_height'] = $img_size[1];
                            }
                            else
                            {
                                //-----------------------------------------------
                                // Show Image..
                                //-----------------------------------------------

                                $this->_show_non_gd();

                            }
                        }
                    }
                }
                else if ( $remap[ $img_size[2] ] == 'JPG' )
                {
                    if ( function_exists( 'imagecreatefromjpeg') )
                    {
                        if ( $image = @imagecreatefromjpeg( $this->in_file_complete ) )
                        {
                            $this->image_type = 'jpg';
                        }
                        else
                        {
                            if ( $this->out_type == 'file' )
                            {
                                $return['thumb_width']     = $this->desired_width;
                                $return['thumb_height']    = $this->desired_height;
                                $return['thumb_location']  = $this->in_file_name;
                                $return['original_width']  = $img_size[0];
                                $return['original_height'] = $img_size[1];
                            }
                            else
                            {
                                //-----------------------------------------------
                                // Show Image..
                                //-----------------------------------------------

                                $this->_show_non_gd();

                            }
                        }
                    }
                }

                //----------------------------------------------------
                // Did we get a return from imagecreatefrom?
                //----------------------------------------------------

                if ( $image )
                {
                    if ( $this->gd_version == 1 )
                    {
                        $thumb = @imagecreate( $im['img_width'], $im['img_height'] );
                        @imagecopyresized( $thumb, $image, 0, 0, 0, 0, $im['img_width'], $im['img_height'], $img_size[0], $img_size[1] );
                    }
                    else
                    {
                        $thumb = @imagecreatetruecolor( $im['img_width'], $im['img_height'] );

                        if( $this->image_type == 'png' )
                        {
                            @imagealphablending( $thumb, FALSE );
                            @imagesavealpha( $thumb, TRUE );

                            $transparent = @imagecolorallocatealpha($thumb, 255, 255, 255, 127);
                            @imagefilledrectangle($thumb, 0, 0, $im['img_width'], $im['img_height'], $transparent);
                        }

                        @imagecopyresampled($thumb, $image, 0, 0, 0, 0, $im['img_width'], $im['img_height'], $img_size[0], $img_size[1] );
                    }

                    //-----------------------------------------------
                    // Saving?
                    //-----------------------------------------------

                    if ( $this->out_type == 'file' )
                    {
                        if ( ! $this->out_file_name )
                        {
                            //-----------------------------------------------
                            // Remove file extension...
                            //-----------------------------------------------

                            $this->out_file_name = preg_replace( "/^(.*)\..+?$/", "\\1", $this->in_file_name ) . '_thumb';
                        }

                        if ( function_exists( 'imagepng' ) AND $this->image_type == 'png' )
                        {
                            $this->file_extension = 'png';
                            @imagepng( $thumb, $this->out_file_dir."/".$this->out_file_name.'.png' );
                            @chmod( $this->out_file_dir."/".$this->out_file_name.'.png', 0777 );
                            @imagedestroy( $thumb );
                            @imagedestroy( $image );
                            $return['thumb_location'] = $this->out_file_name.'.png';
                            return $return;
                        }
                        else if ( function_exists( 'imagejpeg' ) )
                        {
                            $this->file_extension = 'jpg';
                            @imagejpeg( $thumb, $this->out_file_dir."/".$this->out_file_name.'.jpg' );
                            @chmod( $this->out_file_dir."/".$this->out_file_name.'.jpg', 0777 );
                            @imagedestroy( $thumb );
                            @imagedestroy( $image );
                            $return['thumb_location'] = $this->out_file_name.'.jpg';
                            return $return;
                        }
                        else
                        {
                            //--------------------------------------
                            // Can't save...
                            //--------------------------------------

                            $return['thumb_width']     = $this->desired_width;
                            $return['thumb_height']    = $this->desired_height;
                            $return['thumb_location']  = $this->in_file_name;
                            $return['original_width']  = $img_size[0];
                            $return['original_height'] = $img_size[1];

                            return $return;
                        }
                    }
                    else
                    {
                        //-----------------------------------------------
                        // Show image
                        //-----------------------------------------------

                        $this->_show_image( $thumb, $this->image_type );

                    }
                }
                else
                {
                    //----------------------------------------------------
                    // Could not GD, return..
                    //----------------------------------------------------

                    if ( $this->out_type == 'file' )
                    {
                        $return['thumb_width']     = $this->desired_width;
                        $return['thumb_height']    = $this->desired_height;
                        $return['thumb_location']  = $this->in_file_name;
                        $return['original_width']  = $img_size[0];
                        $return['original_height'] = $img_size[1];
                    }
                    else
                    {
                        //-----------------------------------------------
                        // Show Image..
                        //-----------------------------------------------

                        $this->_show_non_gd();

                    }

                    return $return;
                }
            }
            //----------------------------------------------------
            // No need to scale..
            //----------------------------------------------------
            else
            {
                if ( $this->out_type == 'file' )
                {
                    $return['thumb_width']     = $img_size[0];
                    $return['thumb_height']    = $img_size[1];
                    $return['original_width']  = $img_size[0];
                    $return['original_height'] = $img_size[1];

                    return false;
                }
                else
                {
                    //-----------------------------------------------
                    // Show Image..
                    //-----------------------------------------------

                    $this->_show_non_gd();

                }
            }
        }
    }     
    
    /**
    * @desc Generates crop thumnbail
    * @access   public
    * @param    void
    * @return   array    [ thumb_width, thumb_height, thumb_location ]
    */
    public function generate_crop_thumbnail()
    {
        $return = array();
        $image  = "";
        $thumb  = "";

        //-----------------------------------
        // Set up paths
        //-----------------------------------

        $this->_clean_paths();

        $remap  = array( 1 => 'GIF', 2 => 'JPG', 3 => 'PNG', 4 => 'SWF', 5 => 'PSD', 6 => 'BMP' );

        if ( $this->desired_width and $this->desired_height )
        {
            //----------------------------------------------------
            // Tom Thumb!
            //----------------------------------------------------

            $img_size = array();

            if ( $this->in_type == 'file' )
            {
                $img_size = @GetImageSize( $this->in_file_complete );
            }

            if ( $img_size[0] < 1 and $img_size[1] < 1 )
            {
                $img_size    = array();
                $img_size[0] = $this->desired_width;
                $img_size[1] = $this->desired_height;

                $return['thumb_width']    = $this->desired_width;
                $return['thumb_height']   = $this->desired_height;

                if ( $this->out_type == 'file' )
                {
                    $return['thumb_location'] = $this->in_file_name;
                    return $return;
                }
                else
                {
                    //----------------------------------------------------
                    // Show image
                    //----------------------------------------------------

                    $this->_show_non_gd();
                }
            }

            //----------------------------------------------------
            // Do we need to scale?
            //----------------------------------------------------

            if ( ( $img_size[0] > $this->desired_width ) OR ( $img_size[1] > $this->desired_height ) )
            {
                //-----------------------------------------------
                // GD functions available?
                //-----------------------------------------------

                if ( $remap[ $img_size[2] ] == 'GIF' )
                {
                    if ( function_exists( 'imagecreatefromgif') )
                    {
                        if ( $image = @imagecreatefromgif( $this->in_file_complete ) )
                        {
                            $this->image_type = 'gif';
                        }
                        else
                        {
                            if ( $this->out_type == 'file' )
                            {
                                $return['thumb_width']    = $this->desired_width;
                                $return['thumb_height']   = $this->desired_height;
                                $return['thumb_location'] = $this->in_file_name;
                            }
                            else
                            {
                                //-----------------------------------------------
                                // Show Image..
                                //-----------------------------------------------

                                $this->_show_non_gd();

                            }
                        }
                    }
                }
                else if ( $remap[ $img_size[2] ] == 'PNG' )
                {
                    if ( function_exists( 'imagecreatefrompng') )
                    {
                        if ( $image = @imagecreatefrompng( $this->in_file_complete ) )
                        {
                            $this->image_type = 'png';
                        }
                        else
                        {
                            if ( $this->out_type == 'file' )
                            {
                                $return['thumb_width']    = $this->desired_width;
                                $return['thumb_height']   = $this->desired_height;
                                $return['thumb_location'] = $this->in_file_name;
                            }
                            else
                            {
                                //-----------------------------------------------
                                // Show Image..
                                //-----------------------------------------------

                                $this->_show_non_gd();

                            }
                        }
                    }
                }
                else if ( $remap[ $img_size[2] ] == 'JPG' )
                {
                    if ( function_exists( 'imagecreatefromjpeg') )
                    {
                        if ( $image = @imagecreatefromjpeg( $this->in_file_complete ) )
                        {
                            $this->image_type = 'jpg';
                        }
                        else
                        {
                            if ( $this->out_type == 'file' )
                            {
                                $return['thumb_width']    = $this->desired_width;
                                $return['thumb_height']   = $this->desired_height;
                                $return['thumb_location'] = $this->in_file_name;
                            }
                            else
                            {
                                //-----------------------------------------------
                                // Show Image..
                                //-----------------------------------------------

                                $this->_show_non_gd();

                            }
                        }
                    }
                }

                //----------------------------------------------------
                // Did we get a return from imagecreatefrom?
                //----------------------------------------------------

                if ( $image )
                {
                    if ( $this->gd_version == 1 )
                    {
                        $cw = $this->desired_width; // canvas width
                        $ch = $this->desired_height; // canvas height

                        $iw = $img_size[0]; // image width
                        $ih = $img_size[1]; // image height

                        $tyle1 = $iw / $ih;
                        $tyle2 = $cw / $ch;

                        if ($tyle1 >= $tyle2)
                        {
                            $z = round($ih / $ch * $cw);
                            $crw = round(($iw - $z)/2);
                            $crh = 0;
                        }

                        if ($tyle1 < $tyle2)
                        {
                            $z = round($iw / $cw * $ch);
                            $crh = round(($ih - $z)/2);
                            $crw = 0;
                        }

                        $nw = $iw - $crw*2; // new width
                        $nh = $ih - $crh*2; // new height

                        $thumb = @imagecreate( $cw, $ch );
                        @imagecopyresized( $thumb, $image, 0, 0, $crw, $crh, $cw, $ch, $nw, $nh );
                    }
                    else
                    {
                        $cw = $this->desired_width; // canvas width
                        $ch = $this->desired_height; // canvas height

                        $iw = $img_size[0]; // image width
                        $ih = $img_size[1]; // image height

                        $tyle1 = $iw / $ih;
                        $tyle2 = $cw / $ch;

                        if ($tyle1 >= $tyle2)
                        {
                            $z = round($ih / $ch * $cw);
                            $crw = round(($iw - $z)/2);
                            $crh = 0;
                        }

                        if ($tyle1 <= $tyle2)
                        {
                            $z = round($iw / $cw * $ch);
                            $crh = round(($ih - $z)/2);
                            $crw = 0;
                        }

                        $nw = $iw - $crw*2; // new width
                        $nh = $ih - $crh*2; // new height

                        $thumb = @imagecreatetruecolor( $cw, $ch );
                        @imagecopyresampled($thumb, $image, 0, 0, $crw, $crh, $cw, $ch, $nw, $nh );
                    }

                    //-----------------------------------------------
                    // Saving?
                    //-----------------------------------------------

                    if ( $this->out_type == 'file' )
                    {
                        if ( ! $this->out_file_name )
                        {
                            //-----------------------------------------------
                            // Remove file extension...
                            //-----------------------------------------------

                            $this->out_file_name = preg_replace( "/^(.*)\..+?$/", "\\1", $this->in_file_name ) . '_thumb';
                        }

                        if ( function_exists( 'imagejpeg' ) )
                        {
                            $this->file_extension = 'jpg';
                            @imagejpeg( $thumb, $this->out_file_dir."/".$this->out_file_name.'.jpg' );
                            @chmod( $this->out_file_dir."/".$this->out_file_name.'.jpg', 0777 );
                            @imagedestroy( $thumb );
                            @imagedestroy( $image );
                            $return['thumb_location'] = $this->out_file_name.'.jpg';
                            return $return;
                        }
                        else if ( function_exists( 'imagepng' ) )
                        {
                            $this->file_extension = 'png';
                            @imagepng( $thumb, $this->out_file_dir."/".$this->out_file_name.'.png' );
                            @chmod( $this->out_file_dir."/".$this->out_file_name.'.png', 0777 );
                            @imagedestroy( $thumb );
                            @imagedestroy( $image );
                            $return['thumb_location'] = $this->out_file_name.'.png';
                            return $return;
                        }
                        else
                        {
                            //--------------------------------------
                            // Can't save...
                            //--------------------------------------

                            $return['thumb_width']    = $this->desired_width;
                            $return['thumb_height']   = $this->desired_height;
                            $return['thumb_location'] = $this->in_file_name;

                            return $return;
                        }
                    }
                    else
                    {
                        //-----------------------------------------------
                        // Show image
                        //-----------------------------------------------

                        $this->_show_image( $thumb, $this->image_type );

                    }
                }
                else
                {
                    //----------------------------------------------------
                    // Could not GD, return..
                    //----------------------------------------------------

                    if ( $this->out_type == 'file' )
                    {
                        $return['thumb_width']    = $this->desired_width;
                        $return['thumb_height']   = $this->desired_height;
                        $return['thumb_location'] = $this->in_file_name;
                    }
                    else
                    {
                        //-----------------------------------------------
                        // Show Image..
                        //-----------------------------------------------

                        $this->_show_non_gd();

                    }

                    return $return;
                }
            }
            //----------------------------------------------------
            // No need to scale..
            //----------------------------------------------------
            else
            {
                if ( $this->out_type == 'file' )
                {
                    $return['thumb_width']    = $img_size[0];
                    $return['thumb_height']   = $img_size[1];

                    return false;
                }
                else
                {
                    //-----------------------------------------------
                    // Show Image..
                    //-----------------------------------------------

                    $this->_show_non_gd();

                }
            }
        }
    } 
      /**
    * @desc Show GD image
    * @access   private
    * @param    string    Thumbnail data
    * @param    string    Thumbnail type (gif, png, jpg)
    * @return void
    * @internal
    */
    private function _show_image( $thumb, $type )
    {
        flush();

        if ( $type == 'gif' )
        {
            @header('Content-type: image/gif');
        }
        else if ( $type == 'png' )
        {
            @header('Content-Type: image/png' );
        }
        else
        {
            @header('Content-Type: image/jpeg' );
        }

        print $thumb;

        exit();
    } 

    /**
    * @desc Show a NON GD image
    * @access   private
    * @param    void
    * @return   void
    * @internal
    */
    private function _show_non_gd()
    {
        $file_extension = preg_replace( ".*\.(\w+)$", "\\1", $this->in_file_name );
        $file_extension = strtolower( $file_extension );
        $file_extension = $file_extension == 'jpeg' ? 'jpg' : $file_extension;

        if ( strstr( ' gif jpg png ', ' '.$file_extension.' ' ) )
        {
            if ( $data = @file_get_contents( $this->in_file_complete ) )
            {
                $this->_show_image( $data, $file_extension );
            }
        }
    }                 

    /**
    * @desc Scale an image
    * @access   public
    * @param    array    [ cur_height, cur_width, max_width, max_height ]
    * @return    array    [ img_height, img_width ]
    */
    public function scale_image($arg)
    {
        // max_width, max_height, cur_width, cur_height

        $ret = array(
                      'img_width'  => $arg['cur_width'],
                      'img_height' => $arg['cur_height']
                    );

        if ( $arg['cur_width'] > $arg['max_width'] )
        {
            $ret['img_width']  = $arg['max_width'];
            $ret['img_height'] = ceil( ( $arg['cur_height'] * ( ( $arg['max_width'] * 100 ) / $arg['cur_width'] ) ) / 100 );
            $arg['cur_height'] = $ret['img_height'];
            $arg['cur_width']  = $ret['img_width'];
        }

        if ( $arg['cur_height'] > $arg['max_height'] )
        {
            $ret['img_height']  = $arg['max_height'];
            $ret['img_width']   = ceil( ( $arg['cur_width'] * ( ( $arg['max_height'] * 100 ) / $arg['cur_height'] ) ) / 100 );
        }


        return $ret;
    }  
}
?>
